﻿package com.dykj.apps.web.sysmanager.dao;

import java.util.ArrayList;
import java.util.List;
import com.dykj.platform.framework.exception.DatabaseException;
import com.dykj.platform.framework.dao.AbstractPublicDAO;
public class SysAclDAOImpl extends AbstractPublicDAO implements ISysAclDAO{
	private static final long serialVersionUID = 1L;
/**
 * 查询所有userid创建的角色
 */
	public List findAllRole(String userid) throws DatabaseException {
		List list = this.query("from SysRole s where s.creator='"+userid+"'");
		return list;
	}
	/**
	 * 查询roleid下的所有的授权
	 * @param roleid
	 * @return
	 * @throws DatabaseException
	 */
	public List findFunctionidByRoleid(String roleid)throws DatabaseException{
		List list = this.query("from SysAcl s where s.roleid="+roleid);
		return list;
	}
/***
 * 删除角色ID为roleid的所有角色
 */
	public int deleteAcl(String roleid) throws DatabaseException {
		String hql = "delete SysAcl s where s.roleid="+roleid;
		return this.execDML(hql);
	}
	
    //根据自身角色查询出自己下级全部角色
    public List findRolesByRoleid(String role) throws DatabaseException {
    	List resultList = new ArrayList();
    	StringBuffer sb = new StringBuffer();
    	    sb.append("select distinct r.* from sysrole r,sysuser u where r.roleid = u.roleid and u.groupid"); //根据机构ID查询所有角色
    	    sb.append(" in(");
    	    sb.append("select distinct g.groupid from sysgroup g connect by g.parentid = prior g.groupid start with g.parentid"); //根据机构ID查询下面所有的子机构ID
    	    sb.append(" in(");
    	    sb.append("select distinct u.groupid from sysrole r,sysuser u where r.roleid = u.roleid and r.roleid = '"); //根据角色查询所有的机构ID
    	    sb.append(role);
    	    sb.append("'))");
    	    resultList = jdbcTemplate.queryForList(sb.toString());
    	return resultList;
    }

}
